<template>
  <div style='width: 100%'>
    <el-form :inline='true'>
      <el-form-item label='年份选择'>
        <el-select
          v-model='value'
          placeholder='请选择年份'
          @change='selectTime'
        >
          <el-option
            v-for='item in years'
            :key='item.value'
            :label='item.lable'
            :value='item.value'
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=''>
        <el-button type='primary' v-on:click='applyDownload'
          >数据导出</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 对应弹框EnvironmentalConsultTbActivityWindow -->
    <div>
      <el-dialog :visible.sync='windowVisible' append-to-body>
        <EnvironmentalConsultTbActivityWindow
          v-if='windowVisible'
          ref='popWindow'
        ></EnvironmentalConsultTbActivityWindow>
        <span slot='footer' class='dialog-footer'>
          <el-button @click='windowVisible = false'>取消</el-button>
          <el-button type='primary' @click='windowVisible = false'
            >确定</el-button
          >
        </span>
      </el-dialog>
    </div>
    <el-row style='height: 450px; width: 1300px'>
      <el-col :span='24'>
        <el-table
          :data='tableData.slice((pageNo - 1) * page_size, pageNo * page_size)'
          size='mini'
          style='width: 100%'
          header-cell-class-name='table-header-gray'
          v-loading='isShowloading'
          border='1px solid gray'
        >
          <el-table-column
            type='index'
            align='center'
            label='序号'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='clueName'
            align='center'
            label='信息提供人'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='projectTrack'
            align='center'
            label='项目前期跟踪'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='keyName'
            align='center'
            label='关键因素项目成功推动'
            width='150'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='contracts'
            align='center'
            label='成功落地签订合同'
            width='150'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strProCodeGetDate'
            align='center'
            label='领取编号日期'
            width='150'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='projectCode'
            align='center'
            label='项目编号'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='projectName'
            align='center'
            label='项目名称'
            width='150'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='customerNamae'
            align='center'
            label='业主名称'
            width='150'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strContractGetDate'
            align='center'
            label='领取合同日期'
            width='180'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strContractGetState'
            align='center'
            label='合同收回情况'
            width='180'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strContractAmount'
            align='center'
            label='合同金额（元）'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='businessType'
            align='center'
            label='项目类型'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='projectManager'
            align='center'
            label='项目经理'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='areaName'
            align='center'
            label='项目区域'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop=''
            align='center'
            label='审批部门'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strEngineerInvestment'
            align='center'
            label='项目投资（元）'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strReportingTime'
            align='center'
            label='上报报批报告时间'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <!-- <el-table-column prop='expertFee' align='center' label='已提计件绩效金额（元）'  width='160' show-overflow-tooltip></el-table-column> -->
          <el-table-column
            prop='strSettlementIncome'
            align='center'
            label='结算收入（元）'
            width='120'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strExpertFee'
            align='center'
            label='专家费（元）'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strSettlementTime'
            align='center'
            label='结算时间'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strBackAmount'
            align='center'
            label='应收款（元）'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strReceivedAmount'
            align='center'
            label='已回款（元）'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strRecordTime'
            align='center'
            label='备案时间'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='strProStstus'
            align='center'
            label='项目进展'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop='remark'
            align='center'
            label='备注'
            width='100'
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label='操作'
            align='center'
            fixed='right'
            width='100'
          >
            <template slot-scope='scope'>
              <el-button
                type='text'
                @click='handleInfo(scope.$index, scope.row)'
                icon='el-icon-view'
                size='mini'
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-row type='flex' justify='end' style='margin-top: 10px'>
          <el-pagination
            background
            @size-change='handleSizeChange'
            @current-change='handleCurrentChange'
            :current-page='pageNo'
            :page-size='page_size'
            :page-sizes='[10, 20, 30]'
            layout='total, prev, pager, next, sizes'
            :total='total'
          ></el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import EnvironmentalConsultTbActivityWindow from '@/components/views/EnvironmentalConsultTbActivityWindow';
import InvitationStatisticsTable from '@/api/BigDataAnalysis/InvitationStatisticsTable';
import { baseUrl } from '../../core/config/development';
export default {
  components: {
    EnvironmentalConsultTbActivityWindow
  },
  created () {
    //  this.loadTimes();
  },
  data () {
    return {
      windowVisible: false,
      addOperate: undefined,
      tableData: [],
      years: [],
      states: [
        {
          value: '全部',
          lable: '全部'
        },
        {
          value: '进行中',
          lable: '进行中'
        },
        {
          value: '已完成',
          lable: '已完成'
        }
      ],
      value: '',
      value1: '全部',
      total: 0,
      page_size: 10,
      pageNo: 1,
      isShowloading: false,
      year: '',
      state: ''
    };
  },
  directives: {
    focus: {
      // 指令的定义
      inserted: function (el) {
        el.focus();
      }
    }
  },
  mounted: function () {
    this.loadTableData();
    this.loadYears();
  },
  methods: {
    loadYears () {
      let currentYear = new Date().getFullYear();
      this.value = currentYear;
      this.year = currentYear;
      this.years = [];
      this.years.push({ value: '全部', lable: '全部' });
      for (let i = 0; i < 11; i++) {
        this.years.push({
          value: currentYear - i,
          label: currentYear - i + '年'
        });
      }
    },
    /* 部门下拉框  */
    yearFocus () {
      const _this = this;
      this.axios
        .get('http://localhost:8082/yearall/getYearEnvir')
        .then(function (resp) {
          _this.formInline.deptData = resp.data;
        });
    },
    // 年份选择
    selectTime (data) {
      this.year = data;
      this.loadTableData();
    },
    /**
     * 获取表格数据
     */
    loadTableData () {
      let params = {
        size: this.page_size,
        current: this.pageNo,
        yearall: this.year,
        state: this.state
      };
      return new Promise((resolve, reject) => {
        InvitationStatisticsTable.list(this, params)
          .then((res) => {
            this.tableData = res.data.records;
            this.total = res.data.total;
          })
          .catch((e) => {
            reject(e);
          });
      });
    },
    // 分页导航
    handleCurrentChange (val) {
      this.pageNo = val;
      this.loadTableData();
    },
    handleSizeChange (val) {
      this.page_size = val;
      this.loadTableData();
    },
    currentChange (val) {
      this.pageNo = val;
      this.loadTableData();
    },
    // excel导出
    ExportTable () {},
    // 导出
    // exportExcel(){
    //   exportWithdrawExcelAPI(this.formInline).then(res => {
    //     if(res.size > 0){
    //       const content = res
    //       const blob = new Blob([content])
    //       const fileName = '提现审核表.xlsx'
    //       if ('download' in document.createElement('a')) { // 非IE下载
    //         const elink = document.createElement('a')
    //         elink.download = fileName
    //         elink.style.display = 'none'
    //         elink.href = URL.createObjectURL(blob)
    //         document.body.appendChild(elink)
    //         elink.click()
    //         URL.revokeObjectURL(elink.href) // 释放URL 对象
    //         document.body.removeChild(elink)
    //       } else { // IE10+下载
    //         navigator.msSaveBlob(blob, fileName)
    //       }
    //       /* this.$message.success('导出成功')*/
    //     }
    //   }).catch(() => {
    //   });
    // },
    applyDownload () {
      // window.location.href = 'http://localhost:6666/api/excel'

      // this.batchId = '20191128093017';

      //   this.$ajax
      //     .get('/plat/checkBatchId', {
      //       params: {
      //         batchId: this.batchId
      //       }
      //     })
      //     .then(res => {
      //       console.log(res);
      //       if(res.data.code=='200'){
      // location.href = 'http://192.168.1.60:8081/plat/outExcel'
      // window.alert(baseUrl);
      var year = this.year;
      // var url = 'http://localhost:8082/apiExcel/environmentalConsultTbExcel?yearall='+ year ;
      var url = baseUrl + 'apiExcel/environmentalConsultTbExcel?yearall=' + year;
      // window.alert(url);
      window.location.href = url;
      //   }else{

      //     alert('偶哦~出错了！')
      //   }
      // });
    },
    handleInfo (index, row) {
      this.windowVisible = true;
      this.addOperate = false;
      this.$nextTick(() => {
        this.$refs.popWindow.dataInit(row);
      });
    }
  }
};
</script>
